package edu.polsl.bio.str.manager.dao;

import edu.polsl.bio.str.common.entity.Chromosome;
import edu.polsl.bio.str.common.entity.Str;
import org.hibernate.Criteria;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import java.util.List;

/**
 * //todo class description
 * <p/>
 * Created on: Jun 14, 2011 1:31:27 PM <br/>
 * <a href="http://www.polsl.pl">www.polsl.pl</a>
 *
 * @author lukasz.olczak@polsl.pl
 */
public class StrDaoImpl extends HibernateDaoSupport implements StrDao {
  /**
   * slf4j Logger.
   */
  private static final Logger log = LoggerFactory.getLogger(StrDaoImpl.class.getName());

  @Override
  public Str getById(Long id) {
    return (Str) getHibernateTemplate().get(Str.class, id);
  }

  @Override
  public List<Str> findAll(Long individualId, Long chromosomeId) {
    DetachedCriteria query = DetachedCriteria.forClass(Str.class).add(Restrictions.eq("individualId", individualId))
        .add(Restrictions.eq("chromosomeId", chromosomeId)).addOrder(Order.asc("start"));

    return getHibernateTemplate().findByCriteria(query);
  }
}
